<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>&#x64CD;&#x4F5C; | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>&#x64CD;&#x4F5C;</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>操作</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/manipulating/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/03-manipulating/00-intro.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
<p>&#x4E00;&#x65E6;&#x6709;&#x4E86; <code>Moment</code>&#xFF0C;&#x5219;&#x53EF;&#x80FD;&#x9700;&#x8981;&#x4EE5;&#x67D0;&#x4E9B;&#x65B9;&#x5F0F;&#x5BF9;&#x5176;&#x8FDB;&#x884C;&#x64CD;&#x4F5C;&#x3002;
&#x6709;&#x5F88;&#x591A;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x5E2E;&#x52A9;&#x5904;&#x7406;&#x6B64;&#x9700;&#x6C42;&#x3002;</p>
<p>Moment.js &#x4F7F;&#x7528;<a href="javascript:window.open('http://nodejs.cn/s/LU5Lu3');" target="_blank" rel="nofollow">&#x6D41;&#x5F0F;&#x7684;&#x63A5;&#x53E3;&#x6A21;&#x5F0F;</a>&#xFF0C;&#x4E5F;&#x79F0;&#x4E3A;<a href="javascript:window.open('http://nodejs.cn/s/bAPW1x');" target="_blank" rel="nofollow">&#x65B9;&#x6CD5;&#x94FE;</a>&#x3002;
&#x8FD9;&#x4F7F;&#x5F97;&#x53EF;&#x4EE5;&#x6267;&#x884C;&#x4EE5;&#x4E0B;&#x75AF;&#x72C2;&#x7684;&#x64CD;&#x4F5C;&#x3002;</p>
<pre><code class="language-javascript">moment().add(7, &apos;days&apos;).subtract(1, &apos;months&apos;).year(2009).hours(0).minutes(0).seconds(0);
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF1A;moment &#x662F;&#x53EF;&#x53D8;&#x7684;&#x3002;
&#x8C03;&#x7528;&#x4EFB;&#x4F55;&#x4E00;&#x79CD;&#x64CD;&#x4F5C;&#x65B9;&#x6CD5;&#x90FD;&#x4F1A;&#x6539;&#x53D8;&#x539F;&#x59CB;&#x7684; moment&#x3002;</p>
<p>&#x5982;&#x679C;&#x8981;&#x521B;&#x5EFA;&#x526F;&#x672C;&#x5E76;&#x5BF9;&#x5176;&#x8FDB;&#x884C;&#x64CD;&#x4F5C;&#xFF0C;&#x5219;&#x5E94;&#x5728;&#x64CD;&#x4F5C; moment &#x4E4B;&#x524D;&#x4F7F;&#x7528; <code>moment#clone</code>&#x3002;
<a href="javascript:window.open('http://nodejs.cn/s/mdyaB3');" target="_blank" rel="nofollow">&#x67E5;&#x770B;&#x6709;&#x5173;&#x514B;&#x9686;&#x7684;&#x66F4;&#x591A;&#x4FE1;&#x606F;</a>&#x3002;</p>
					</div>
          <div id="content_right">
<p>Once you have a <code>Moment</code>, you may want to manipulate it in some way. There are a number of methods to help with this.</p>
<p>Moment.js uses the <a href="javascript:window.open('https://en.wikipedia.org/wiki/Fluent_interface');" target="_blank" rel="nofollow">fluent interface pattern</a>, also known as <a href="javascript:window.open('https://en.wikipedia.org/wiki/Method_chaining');" target="_blank" rel="nofollow">method chaining</a>. This allows you to do crazy things like the following.</p>
<pre><code class="language-javascript">moment().add(7, &apos;days&apos;).subtract(1, &apos;months&apos;).year(2009).hours(0).minutes(0).seconds(0);
</code></pre>
<p><strong>Note:</strong> It should be noted that moments are mutable. Calling any of the manipulation methods will change the original moment.</p>
<p>If you want to create a copy and manipulate it, you should use <code>moment#clone</code> before manipulating the moment. <a href="#/parsing/moment-clone/" target="_blank" rel="nofollow">More info on cloning.</a></p>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>